home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / netdrv10.zip / NETDRIVE.PAS < prev   
Pascal/Delphi Source File  |  1992-10-06  |  3KB  |  116 lines

  1. PROGRAM NetDrive;
  2.  
  3. USES
  4.     Dos, Crt, TPEnv2;
  5.  
  6. {
  7. TPEnv2 was made from TPENV.ARC downloaded from the PCVENB Lib 6 (TurboPower).
  8. I created a ParentEnv() procedure from parts of provided procedures.
  9. Thank you TurboPower !
  10. }
  11.  
  12. VAR
  13.     DirExists : SearchRec;
  14.     DriveList : String[21];
  15.     ChkDrive  : String[1];
  16.     CHkFile   : String[18];
  17.     NovDrive  : String[2];
  18.     Counter   : Integer;
  19.     Percent1  : String[20];
  20.     Quiet     : Boolean;
  21.  
  22. PROCEDURE Syntax;
  23. Begin
  24. WriteLn('NETDRIVE v1.0');
  25. WriteLn('');
  26. WriteLn('A NetWare utility by Danny Dillon  (70214,2221)');
  27. WriteLn('');
  28. WriteLn('NETDRIVE sets the environmental variable "NETDRIVE" to the first drive where');
  29. WriteLn('LOGIN.EXE is found, ( starting with F: and searching through Z: ). It is meant');
  30. WriteLn('to be used in a batch file immediately following NETx, allowing the supervisor');
  31. WriteLn('to write the same batch file for for all workstations, without having to allow');
  32. WriteLn('for a different lastdrive. ');
  33. WriteLn('');
  34. WriteLn('     ...');
  35. WriteLn('     NETX');
  36. WriteLn('     NETDRIVE <Q>');
  37. WriteLn('     If ErrorLevel 0 %NETDRIVE%\LOGIN\LOGIN');
  38. WriteLn('');
  39. WriteLn('Optional Parameter Q turns off console error messages.');
  40. WriteLn('Any other other parameter displays this screen.');
  41. WriteLn('Errorlevel 0 indicates \LOGIN\LOGIN.EXE was found & NETDRIVE set.');
  42. WriteLn('Errorlevel 1 indicates \LOGIN\LOGIN.EXE was not found.');
  43. WriteLn('ErrorLevel 2 indicated a problem writing to the environment.');
  44. WriteLn('');
  45. WriteLn('This program has been tested with MS & IBM DOS 3.3 & up !');
  46. WriteLn(' ');
  47. end;
  48.  
  49. Begin {MAIN PROGRAM}
  50.     Quiet := False;
  51.     DriveList := 'FGHIJKLMNOPQRSTUVWXYZ';
  52.     If ParamCount <> 0 then begin
  53.         Percent1 := ParamStr(1);
  54.         Percent1[1] := Upcase(Percent1[1]);
  55.         If Percent1 <> 'Q' then Syntax;
  56.         Quiet := True;
  57.     end;
  58.  
  59.     NovDrive := '';
  60.     For Counter := 1 to 21 do
  61.         Begin
  62.             ChkDrive := DriveList[Counter];
  63.             CHkFile := Concat(ChkDrive,':\LOGIN\LOGIN.EXE');
  64.             FindFirst(ChkFile, AnyFile, DirExists);
  65.             If (DosError = 0) then Begin
  66.                 NovDrive := Concat(ChkDrive,':');
  67.                 Counter := 21;
  68.             end;
  69.         end;
  70.     If Length(NovDrive) < 2 then Begin
  71.         If NOT Quiet then WriteLn('NETDRIVE ERROR: \LOGIN\LOGIN.EXE not found !');
  72.         Halt(1);
  73.     end;
  74.     ParentEnv(E);
  75.     if not SetEnvStr(E, 'NETDRIVE', NovDrive) then Begin
  76.         If NOT Quiet then WriteLn('Not enough space in environment to add NETDRIVE.');
  77.         Halt(2);
  78.     end;
  79.  
  80. { The following is the code for the ParentEnv procedure I added to TPENV.
  81.   It was derived from parts of CurrentEnv & MasterEnv.
  82.  
  83.   procedure ParentEnv(var Env : EnvRec);
  84.   var
  85.     ESeg : Word;
  86.     Mcb : Word;
  87.      PSeg : Word;
  88.      Owner : Word;
  89.   begin
  90.     with Env do begin
  91.       ClearEnvRec(Env);
  92.         Owner := MemW[0:(2+4*$2E)];
  93.         PSeg := MemW[PrefixSeg:$16];
  94.         ESeg := MemW[PSeg:$2C];
  95.         if Eseg = 0 then begin
  96.           Mcb := Owner+MemW[Mcb:3];
  97.           if (Mem[Mcb:0] <> Byte('M')) or (MemW[Mcb:1] <> Owner) then
  98.              Exit;
  99.           Eseg := Mcb+1;
  100.         end else
  101.           Mcb := Eseg-1;
  102.         EnvSeg := ESeg;
  103.         EnvLen := MemW[Mcb:3] shl 4;
  104.      end;
  105.   end;
  106.  
  107. }
  108. End.
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.